﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using ClassLibrary.Entity;
using System.Data;

namespace ClassLibrary.DAO
{
    public class TblLoanPhoneDAO
    {
        DBService _db = null;
        public TblLoanPhoneDAO(string ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }
        public bool InsUpd_TblLoanPhone(TblLoanPhone LoanPhone, int mode)
        {
            bool flag = false;
            try
            {
                _db.ExeSP_NonQuery("sp_TblLoanPhone_InsUpd",
                    new string[] {"@LoanID", "@JobID", "@CustomerID", "@LPhoneID", "@Brand", "@Model", "@IMENo", "@AccessoriesIncluded", "@AmountDeposited", "@DepositeTaken", 
                                  "@PaymentMethod", "@PaymentRef", "@LoanFee", "@DateOut", "@DateIn", "@DepositeRefunded", "@Notes", "@mode" },
                    new object[] {LoanPhone.LoanID, LoanPhone.JobID, LoanPhone.CustomerID, LoanPhone.LPhoneID, LoanPhone.Brand, LoanPhone.Model, LoanPhone.IMENo, LoanPhone.AccessoriesIncluded, LoanPhone.AmountDeposited, LoanPhone.DepositeTaken,
                                  LoanPhone.PaymentMethod, LoanPhone.PaymentRef, LoanPhone.LoanFee, LoanPhone.DateOut, LoanPhone.DateIn, LoanPhone.DepositeRefunded, LoanPhone.Notes, mode},
                    CommandType.StoredProcedure);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }

        public DataTable LoadLoanPhoneByJobID(int JobID)
        {
            DataTable dt = null;
            try 
            {
                dt = _db.ExeSP_DataTable("select * from TblLoanPhone where JobID = @JobID",
                    new string[] { "@JobID" },
                    new object[] { JobID},
                    CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }
    }
}
